<!-- 功能：IPSAN管理 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月22日 22:58:00 -->
<template>
  <a-tabs v-model:activeKey="activeKey" type="card" class="y-tabs">
    <a-tab-pane key="target" tab="Target">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openTianJiaTargetModal">
                <template #icon>
                  <plus-outlined />
                </template>
                添加Target
              </a-button>
              <!-- 弹窗 - 添加Target -->
              <tianJiaTargetModal v-model:visible="visibleTianJiaTargetModal"></tianJiaTargetModal>
              <a-button type="link" class="y-btn y-close-ipsan-fuwu" @click="tingZhiIpsanFuWu">
                <template #icon>
                  <poweroff-outlined />
                </template>
                停止IPSAN服务
              </a-button>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueTarget">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceTarget" :columns="columnsTarget" class="y-table" :pagination="paginationTarget">
        </a-table>
      </a-card>
    </a-tab-pane>

    <a-tab-pane key="chapRenZhengYongHu" tab="CHAP认证用户">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openXinJianZhangHuModal">
                <template #icon>
                  <plus-outlined />
                </template>
                新建账户
              </a-button>
              <!-- 弹窗 - 新建账户 -->
              <xinJianZhangHuModal v-model:visible="visibleXinJianZhangHuModal"></xinJianZhangHuModal>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueChapRenZhengYongHu">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceChapRenZhengYongHu" :columns="columnsChapRenZhengYongHu" class="y-table" :pagination="paginationChapRenZhengYongHu">
        </a-table>
      </a-card>
    </a-tab-pane>
  </a-tabs>
</template>

<script setup>
import xinJianZhangHuModal from './modal/xinJianZhangHuModal.vue'
import tianJiaTargetModal from './modal/tianJiaTargetModal.vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { Modal } from 'ant-design-vue'
const activeKey = ref('target')

// -- Target
const visibleTianJiaTargetModal = ref(false)

const openTianJiaTargetModal = () => {
  visibleTianJiaTargetModal.value = true
}

const tingZhiIpsanFuWu = () => {
  Modal.confirm({
    title: '确认操作',
    icon: h(ExclamationCircleOutlined),
    content: '您确定要停止IPSAN服务?',
    okText: '确定',
    okType: 'danger',
    cancelText: '取消',
    onOk() {
      console.log('OK')
    },
    onCancel() {
      console.log('Cancel')
    }
  })
}
const searchValueTarget = ref('')

// 表格列
const columnsTarget = ref([
  {
    title: 'Target名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.name.localeCompare(b.name),
      multiple: 1
    }
  },
  {
    title: '组名',
    dataIndex: 'groupName',
    key: 'groupName',
    align: 'center',
    sorter: {
      compare: (a, b) => a.groupName.localeCompare(b.groupName),
      multiple: 2
    }
  },
  {
    title: '设备名称',
    dataIndex: 'sheBeiMingCheng',
    key: 'sheBeiMingCheng',
    align: 'center',
    sorter: {
      compare: (a, b) => a.sheBeiMingCheng.localeCompare(b.sheBeiMingCheng),
      multiple: 3
    }
  },
  {
    title: '客户端Initiator节点名称',
    dataIndex: 'initiatorName',
    key: 'initiatorName',
    align: 'center',
    sorter: {
      compare: (a, b) => a.initiatorName.localeCompare(b.initiatorName),
      multiple: 3
    }
  }
])

// 表格数据
const dataSourceTarget = ref([
  {
    key: '1',
    name: 'Target1',
    groupName: 'Group1',
    sheBeiMingCheng: 'SheBeiMingCheng1',
    initiatorName: 'InitiatorName1'
  },
  {
    key: '2',
    name: 'Target2',
    groupName: 'Group2',
    sheBeiMingCheng: 'SheBeiMingCheng2',
    initiatorName: 'InitiatorName2'
  }
])

// 分页
const paginationTarget = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('IPSAN管理 > Target分页改变>>', page, pageSize)
  }
}

// -- CHAP认证用户
const visibleXinJianZhangHuModal = ref(false)

const openXinJianZhangHuModal = () => {
  visibleXinJianZhangHuModal.value = true
}

const searchValueChapRenZhengYongHu = ref('')

// 表格列
const columnsChapRenZhengYongHu = ref([
  {
    title: '账户名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.name.localeCompare(b.name),
      multiple: 1
    }
  }
])

// 表格数据
const dataSourceChapRenZhengYongHu = ref([
  {
    key: '1',
    name: 'Zu1'
  },
  {
    key: '2',
    name: 'Zu2'
  }
])

// 分页
const paginationChapRenZhengYongHu = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('IPSAN管理 > CHAP认证用户>>', page, pageSize)
  }
}
</script>

<style scoped lang='scss'>
.ant-row {
  margin-bottom: 10px;
}

.y-close-ipsan-fuwu {
  color: red;
}
</style>